// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var leftMenu = require("../leftMenu/leftMenu");
	var topMenu = require("../topMenu/topMenu");
	var router = require("../hash/pageRouter");
	var dialog = require("dialog");
	var html_coldStorage = require("./html_coldStorage.html");
	var validate = require("validate");
	var databind = require("databind");
	var css_financingDetailInfo = require("../financing/financingDetailInfo.css");
	var css_deliveryNotice = require("./deliveryNotice.css");
	var css_platform_main = require("./platform_main.css");
	var css_financeApprove = require("./financeApprove1_5.css");
	var css_detail = require("./pickupDetail.css");
	var js_platform_main = require("./platform_main.js");
	var valuationCal = require("valuationCal");
	var html_inventoryList = require("./html_inventoryList.html");
	var productType;
	var storage = window.sessionStorage;
	var tools = require("tools");
	var fileUuid;
	var constant = require("constant");
	var pageIndex = 1,
		pageSize = 10,
		totalPageCount = 1,
		totalRecordCount = 0; //分页初始化
	var imgSrc;
	var left;
	var financeId;
	var financeAuditId;
	var type = "";
	var interestPart = "";

	var init = function(page) {
		financeId = page.params.financeId;
		financeAuditId = page.params.financeAuditId;
		type = page.params.type;
		left = page.params.left || base.getUrlParam("left");
		
		tools.inquireCommonSelectorByStringList(15, $("#insuranceCompany"));
		tools.inquireCommonSelectorByStringList(16, $("#insuranceType"));
		tools.inquireCommonSelectorByStringList(15, $("#financeApprove1_5 select[name=enterpriseInsurer]"));
		tools.inquireCommonSelectorByStringList(16, $("#financeApprove1_5 select[name=enterpriseInsuranceType]"));
		inquireFinanceApplicationDetail();
		initEvent();
		router.init();
		$(".left").removeClass("none");
		inquireCurrentOperationList();
//		tools.inquireCommonSelectorListByName("计息期间分段", $("#financeApprove1_5 .interestPart"));
	};
	var initEvent = function() {
		//若未登录，则返回登陆页面
		if (base.getData("sid") == null || base.getData("sid") == "" || base.getData("sid") == undefined) {
			top.location.href = "../login/login.html";
		}
		
		//查看审批记录
		$("#financeApprove1_5 .auditRecord").unbind("click").click(function(){
			window.open("../auditRecord/auditRecord.html?recordType=1&recordId=" + financeId);
		});

		
		$("#financeApprove1_5 .showBtn").click(function(){
	    	var bt = $(this).html();
	    	if (bt == "展开") {
	    		$(this).parent().parent().next(".showLink").removeClass("none");
		    	$(this).addClass("open");
		    	$(this).html("收起");
	    		} else if(bt == "收起"){
		    		$(this).parent().parent().next(".showLink").addClass("none");
			    	$(this).removeClass("open");
			    	$(this).html("展开");
		    	}
	    	
	   		});
		
		$("#financeApprove1_5").on("change", "input[name=financeDays]", function(){
			$(".productTable tbody").html("");
			var inte = ($("#financeApprove1_5 input[name=intrerst]").val()/360).toFixed(4);
			var financeDays = $("#financeApprove1_5 input[name=financeDays]").val();
			
			if (financeDays == 0 || financeDays == "" || $("#financeApprove1_5 .interestPart").val() == "") {
				return;
			}
			var array = $("#financeApprove1_5 .interestPart").val().split(' ');
			array.push(financeDays);
			array.push("0");
			array = tools.unique(array);
			array.sort(function(a,b){
            	return a-b;
			});
			
			for (var i = 0; i < array.length - 1; i++) {
				var str = "<tr><td><input type='hidden' name='financeProductInterestItemId' value='0' /><input isNull='1' value='利息' codeName='计息项名称' type='text' name='financeProductInterestItemName'/></td><td><select isNull='1' codeName='利率类型' name='billingType'><option value='1'>固定计息</option><option value='2'>按日计息</option></select></td><td><input isNull='1' value='"+ inte +"' codeName='利率' type='text' name='interestRate'/></td><td><input isNull='1' codeName='起始天' value='"+ (array[i]*1+1) +"' type='text' name='startDay'/></td><td><input isNull='1' codeName='截止天' value='"+ array[i+1] +"' type='text' name='endDay' /></td></tr>";
				$(".productTable tbody").append(str);
			}
		});
		
		$("#financeApprove1_5").on("change", ".interestPart", function(){
			$(".productTable tbody").html("");
			var inte = ($("#financeApprove1_5 input[name=intrerst]").val()/360).toFixed(4);
			var financeDays = $("#financeApprove1_5 input[name=financeDays]").val();
			
			if (financeDays == 0 || financeDays == "" || $("#financeApprove1_5 .interestPart").val() == "") {
				return;
			}
			var array = $("#financeApprove1_5 .interestPart").val().split(' ');
			array.push(financeDays);
			array.push("0");
			array = tools.unique(array);
			array.sort(function(a,b){
            	return a-b;
			});
			for (var i = 0; i < array.length - 1; i++) {
				var str = "<tr><td><input type='hidden' name='financeProductInterestItemId' value='0' /><input isNull='1' value='利息' codeName='计息项名称' type='text' name='financeProductInterestItemName'/></td><td><select isNull='1' codeName='利率类型' name='billingType'><option value='1'>固定计息</option><option value='2'>按日计息</option></select></td><td><input isNull='1' value='"+ inte +"' codeName='利率' type='text' name='interestRate'/></td><td><input isNull='1' codeName='起始天' value='"+ (array[i]*1+1) +"' type='text' name='startDay'/></td><td><input isNull='1' codeName='截止天' value='"+ array[i+1] +"' type='text' name='endDay' /></td></tr>";
				$(".productTable tbody").append(str);
			}
		});
		
		$("#financeApprove1_5 .print").unbind("click").click(function(){
			tools.printit($("#financeApprove1_5"),'preview');
		});
		
//		tools.fileupload($("#auditFile"), null, function(data){
//			var str = '<div class="showAuditIntroDiv"><a target="_blank" class="mas" fileUuid="' + data.result.data[0].fileUuid + '" href="/finance/api/v1.0/downloadFile.file?fileUuid=' + data.result.data[0].fileUuid + '" class="showAuditIntro">' + data.result.data[0].fileName + '</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="deleteProductIntro">x</a></div>'
//			$(".auditFile").before(str);
//			fileUuid = [];
//			for (var j = 0; j < $(".showAuditIntroDiv .mas").length; j++) {
//				fileUuid.push($($(".showAuditIntroDiv .mas")[j]).attr("fileUuid"));
//			}
//			$("#auditMaterials").val(fileUuid);
//		});
		
		$("#financeApprove1_5").on("click", ".showProductIntroDiv .deleteProductIntro", function() {
			$(this).parent().find(".mas").remove();
			fileUuid = [];
			for (var j = 0; j <$(this).parent().parent().find(".showProductIntroDiv .mas").length; j++) {
				fileUuid.push($($("#financeApprove1_5 .showProductIntroDiv .mas")[j]).attr("fileUuid"));
			}
			$(this).parent().parent().find("input[name=filesUuid]").val(fileUuid);
			$(this).parent().remove();
		});
		
		$("#financeApprove1_5").on("click", ".showAuditIntroDiv .deleteProductIntro", function() {
			$(this).parent().remove();
			fileUuid = [];
			for (var j = 0; j < $("#financeApprove1_5 .showAuditIntroDiv .mas").length; j++) {
				fileUuid.push($($("#financeApprove1_5 .showAuditIntroDiv .mas")[j]).attr("fileUuid"));
			}
//			$("#auditMaterials").val(fileUuid);
		});
		
		$("#financeApprove1_5").on("change", "input[name=intrerst]", function() {
			$("#financeApprove1_5 input[name=interestRate]").val(($(this).val()/360).toFixed(4));
			$("#financeApprove1_5 input[name=auditInterest]").val($(this).val());
			$("#financeApprove1_5 .serveExpense").html(tools.formatCurrency($("#financeApprove1_5 .financeAmountInput").val()*$("#financeApprove1_5 .interest").val()/100));
		});
		
		$("#financeApprove1_5").on("change", "input[name=bailRate]", function() {
			$("#financeApprove1_5 input[name=bail]").val($(this).val()*$("#financeApprove1_5 input[name=finalPrice]").val()/100);
		});

		//点击首页
		$(".platform_main").unbind("click").click(function() {
			top.location.href = "../main/platform_main.html";
		});
		//待审批列表
		$(".financeApproveList").unbind("click").click(function() {
			router.route("main/main_finance.html?left=0&financeState=1", true);
		});
		//点击融资申请基本信息
		$(".financeDetailInfo").on("click", function() {
			router.route("main/financingDetailInfo.html?financeId=" + financeId, true);
		});

		//点击证明材料
		$(".evidentiaryCategorys").on("click", function() {
			router.route("main/financingDetailEvidentiaryCategorys.html?financeId=" + financeId, true);
		});
		
		$(".footButton .button-Yes").on("click", function() {
			$("#financeApprove1_5 .financeApproveContent").attr("action", "consentFinanceApplication");
			if ($(".financeAmountInput").val() <= 0) {
				base.alert(2, "允许融资额度要大于0元");
				return;
			}
			
			if ($(".financeAmountInput").val()*1 > $(".applicationAmount").html()*1) {
				dialog.showConfirmDialog("融资审批", "审批金额大于申请金额，是否确认？", function(){
					databind.submitDom($(".financeApproveContent"), function() {
						base.alert(1, "融资评审通过成功");
						router.route("main/main_finance.html?left=0&financeState=1", true);
						inquireFinanceLatestAuditDetail();
						databind.disableInput($(".financeApproveContent"));
						$(".button-Yes").remove();
						$(".button-No").remove();
					});
				});
			} else {
				databind.submitDom($(".financeApproveContent"), function() {
					base.alert(1, "融资评审通过成功");
					router.route("main/main_finance.html?left=0&financeState=1", true);
					inquireFinanceLatestAuditDetail();
					databind.disableInput($(".financeApproveContent"));
					$(".button-Yes").remove();
					$(".button-No").remove();
				});
			}
		});
		
		$("#businessAudit .button-Yes").unbind("click").click(function(){
			if ($("input[name=bailRate]").val()*1 < $("input[name=realBailRate]").val()*1) {
				base.alert(2, "实际保证金比例不能低于最低保证金比例！");
				return;
			}
			
			if ($(".financeAmountInput").val() <= 0) {
				base.alert(2, "允许融资额度要大于0元");
				return;
			}
			
			if ($(".financeAmountInput").val()*1 > $(".applicationAmount").html()*1) {
				base.alert(2, "审批金额不能大于申请金额！");
				return;
			}
			
			var d = $("#financeApprove1_5 .financeAmountInput").val();
			var cm = $("#financeApprove1_5 .data[name=creditLineRemains]").html();
			
			if ((d/10000)*1 > cm*1) {
				base.alert(2, "授信额度不足！");
				return;
			}
			
			$("#financeApprove1_5 .financeApproveContent").attr("action", "supplementBussinessAuditOpinion");
			databind.submitDom($("#financeApprove1_5 .financeApproveContent"), function(data) {
				base.alert(1, "保存成功");
				databind.fillForm($("#businessAudit"), {"businessAuditor": data.datas[0].auditor, "businessAuditDate": data.datas[0].auditDate});
				$.each($(".auditInfo .data"), function() {
					var $this = $(this);
					if ($.trim($this.html()) != "") {
						$this.parents(".auditInfo").show();
					}
				});
				$("#financeApprove1_5 input[name=financeAuditId]").val(data.datas[0].financeAuditId);
			});
		});
		
		$("#businessManageAudit .button-Yes").unbind("click").click(function(){
			$("#financeApprove1_5 .financeApproveContent").attr("action", "supplementBussinessManageAuditOpinion");
			databind.submitDom($("#financeApprove1_5 .financeApproveContent"), function(data) {
				base.alert(1, "保存成功");
				databind.fillForm($("#businessManageAudit"), {"businessManageAuditor": data.datas[0].auditor, "businessManageAuditDate": data.datas[0].auditDate});
				$.each($(".auditInfo .data"), function() {
					var $this = $(this);
					if ($.trim($this.html()) != "") {
						$this.parents(".auditInfo").show();
					}
				});
				$("#financeApprove1_5 input[name=financeAuditId]").val(data.datas[0].financeAuditId);
			});
		});
		
		$("#operationAudit .button-Yes").unbind("click").click(function(){
			$("#financeApprove1_5 .financeApproveContent").attr("action", "supplementOperationAuditOpinion");
			databind.submitDom($("#financeApprove1_5 .financeApproveContent"), function(data) {
				base.alert(1, "保存成功");
				databind.fillForm($("#operationAudit"), {"operationAuditor": data.datas[0].auditor, "operationAuditDate": data.datas[0].auditDate});
				$.each($(".auditInfo .data"), function() {
					var $this = $(this);
					if ($.trim($this.html()) != "") {
						$this.parents(".auditInfo").show();
					}
				});
				$("#financeApprove1_5 input[name=financeAuditId]").val(data.datas[0].financeAuditId);
			});
		});
		
		$("#riskAudit .button-Yes").unbind("click").click(function(){
			if ($(".financeAmountInput").val() <= 0) {
				base.alert(2, "允许融资额度要大于0元");
				return;
			}
			
			if ($(".financeAmountInput").val()*1 > $(".applicationAmount").html()*1) {
				base.alert(2, "审批金额不能大于申请金额！");
				return;
			}
			
			var d = $("#financeApprove1_5 .financeAmountInput").val();
			var cm = $("#financeApprove1_5 .data[name=creditLineRemains]").html();
			
			if ((d/10000)*1 > cm*1) {
				base.alert(2, "授信额度不足！");
				return;
			}
			
			$("#financeApprove1_5 .financeApproveContent").attr("action", "supplementRiskAuditOpinion");
			databind.submitDom($("#financeApprove1_5 .financeApproveContent"), function(data) {
				base.alert(1, "保存成功");
				databind.fillForm($("#riskAudit"), {"riskAuditor": data.datas[0].auditor, "riskAuditDate": data.datas[0].auditDate});
				$.each($(".auditInfo .data"), function() {
					var $this = $(this);
					if ($.trim($this.html()) != "") {
						$this.parents(".auditInfo").show();
					}
				});
				$("#financeApprove1_5 input[name=financeAuditId]").val(data.datas[0].financeAuditId);
			});
		});
		
		$("#operationManageAudit .button-Yes").unbind("click").click(function(){
			$("#financeApprove1_5 .financeApproveContent").attr("action", "supplementOperationManageAuditOpinion");
			databind.submitDom($("#financeApprove1_5 .financeApproveContent"), function(data) {
				base.alert(1, "保存成功");
				databind.fillForm($("#operationManageAudit"), {"operationManageAuditor": data.datas[0].auditor, "operationManageAuditDate": data.datas[0].auditDate});
				$.each($(".auditInfo .data"), function() {
					var $this = $(this);
					if ($.trim($this.html()) != "") {
						$this.parents(".auditInfo").show();
					}
				});
				$("#financeApprove1_5 input[name=financeAuditId]").val(data.datas[0].financeAuditId);
			});
		});
		
		$("#riskMemberAudit .button-Yes").unbind("click").click(function(){
			$("#financeApprove1_5 .financeApproveContent").attr("action", "supplementRiskMemberAuditOpinion");
			databind.submitDom($("#financeApprove1_5 .financeApproveContent"), function(data) {
				base.alert(1, "保存成功");
				databind.fillForm($("#riskMemberAudit"), {"riskMemberAuditor": data.datas[0].auditor, "riskMemberAuditDate": data.datas[0].auditDate});
				$.each($(".auditInfo .data"), function() {
					var $this = $(this);
					if ($.trim($this.html()) != "") {
						$this.parents(".auditInfo").show();
					}
				});
				$("#financeApprove1_5 input[name=financeAuditId]").val(data.datas[0].financeAuditId);
			});
		});
		
//		$("#ceoAudit .button-Yes").unbind("click").click(function(){
//			$("#financeApprove1_5 .financeApproveContent").attr("action", "supplementCeoAuditOpinion");
//			$("#auditMaterials").attr("isNULL", "0");
//			databind.submitDom($("#financeApprove1_5 .financeApproveContent"), function(data) {
//				base.alert(1, "保存成功");
//				databind.fillForm($("#ceoAudit"), {ceoAuditor: data.datas[0].auditor, ceoAuditDate: data.datas[0].auditDate});
//				$.each($(".auditInfo .data"), function() {
//					var $this = $(this);
//					if ($.trim($this.html()) != "") {
//						$this.parents(".auditInfo").show();
//					}
//				});
//				$("#financeApprove1_5 input[name=financeAuditId]").val(data.datas[0].financeAuditId);
//			});
//		});
//		
//		$("#finalAudit .button-Yes").unbind("click").click(function(){
//			$("#financeApprove1_5 .financeApproveContent").attr("action", "supplementFinalAuditOpinion");
//			$("#auditMaterials").attr("isNULL", "0");
//			databind.submitDom($("#financeApprove1_5 .financeApproveContent"), function(data) {
//				base.alert(1, "保存成功");
//				databind.fillForm($("#finalAudit"), {finalAuditor: data.datas[0].auditor, finalAuditDate: data.datas[0].auditDate});
//				$.each($(".auditInfo .data"), function() {
//					var $this = $(this);
//					if ($.trim($this.html()) != "") {
//						$this.parents(".auditInfo").show();
//					}
//				});
//				$("#financeApprove1_5 input[name=financeAuditId]").val(data.datas[0].financeAuditId);
//			});
//		});
		
		//--------------------------------------------
		$("#businessAudit .button-Save").unbind("click").click(function(){
			if ($(".financeAmountInput").val() <= 0) {
				base.alert(2, "允许融资额度要大于0元");
				return;
			}
			
			if ($(".financeAmountInput").val()*1 > $(".applicationAmount").html()*1) {
				base.alert(2, "审批金额不能大于申请金额！");
				return;
			}
			
			var d = $("#financeApprove1_5 .financeAmountInput").val();
			var cm = $("#financeApprove1_5 .data[name=creditLineRemains]").html();
			
			if ((d/10000)*1 > cm*1) {
				base.alert(2, "授信额度不足！");
				return;
			}
			
			$("#financeApprove1_5 .financeApproveContent").attr("action", "submitBussinessAuditOpinion");
			dialog.showConfirmDialog("业务审核", "是否确认提交？提交后不可再次修改。", function(){
				databind.submitDom($("#financeApprove1_5 .financeApproveContent"), function(data) {
					base.alert(1, "提交成功！");
					router.route("main/main_finance.html?left=0&financeState=1", true);
				});
			});
		});
		
		$("#businessManageAudit .button-Save").unbind("click").click(function(){
			$("#financeApprove1_5 .financeApproveContent").attr("action", "submitBussinessManageAuditOpinion");
			dialog.showConfirmDialog("业务领导审核", "是否确认提交？提交后不可再次修改。", function(){
				databind.submitDom($("#financeApprove1_5 .financeApproveContent"), function(data) {
					base.alert(1, "提交成功！");
					router.route("main/main_finance.html?left=0&financeState=1", true);
				});
			});
		});
		
		$("#operationAudit .button-Save").unbind("click").click(function(){
			$("#financeApprove1_5 .financeApproveContent").attr("action", "submitOperationAuditOpinion");
			dialog.showConfirmDialog("财务确认", "是否确认提交？提交后不可再次修改。", function(){
				databind.submitDom($("#financeApprove1_5 .financeApproveContent"), function(data) {
					base.alert(1, "提交成功！");
					router.route("main/main_finance.html?left=0&financeState=1", true);
				});
			});
		});
//		
//		$("#operationManageAudit .button-Save").unbind("click").click(function(){
//			$("#financeApprove1_5 .financeApproveContent").attr("action", "submitOperationManageAuditOpinion");
//			dialog.showConfirmDialog("运营领导审核", "是否确认提交？提交后不可再次修改。", function(){
//				databind.submitDom($("#financeApprove1_5 .financeApproveContent"), function(data) {
//					base.alert(1, "提交成功！");
//					router.route("main/main_finance.html?left=0&financeState=1", true);
//				});
//			});
//		});
		
//		$("#financialAudit .button-Save").unbind("click").click(function(){
//			$("#financeApprove1_5 .financeApproveContent").attr("action", "submitFinancialAuditOpinion");
//			dialog.showConfirmDialog("资金审核", "是否确认提交？提交后不可再次修改。", function(){
//				databind.submitDom($("#financeApprove1_5 .financeApproveContent"), function(data) {
//					base.alert(1, "提交成功！");
//					router.route("main/main_finance.html?left=0&financeState=1", true);
//				});
//			});
//		});
//		
//		$("#financialManageAudit .button-Save").unbind("click").click(function(){
//			$("#financeApprove1_5 .financeApproveContent").attr("action", "submitFinancialManageAuditOpinion");
//			dialog.showConfirmDialog("资金领导审核", "是否确认提交？提交后不可再次修改。", function(){
//				databind.submitDom($("#financeApprove1_5 .financeApproveContent"), function(data) {
//					base.alert(1, "提交成功！");
//					router.route("main/main_finance.html?left=0&financeState=1", true);
//				});
//			});
//		});
		
		$("#riskAudit .button-Save").unbind("click").click(function(){
			
			if ($(".financeAmountInput").val()*1 > $(".applicationAmount").html()*1) {
				base.alert(2, "审批金额不能大于申请金额！");
				return;
			}
			
			var d = $("#financeApprove1_5 .financeAmountInput").val();
			var cm = $("#financeApprove1_5 .data[name=creditLineRemains]").html();
			
			if ((d/10000)*1 > cm*1) {
				base.alert(2, "授信额度不足！");
				return;
			}
			
			$("#financeApprove1_5 .financeApproveContent").attr("action", "submitRiskAuditOpinion");
			dialog.showConfirmDialog("风控审核", "是否确认提交？提交后不可再次修改。", function(){
				databind.submitDom($("#financeApprove1_5 .financeApproveContent"), function(data) {
					base.alert(1, "提交成功！");
					router.route("main/main_finance.html?left=5&financeState=23", true);
				});
			});
		});
		
		$("#riskMemberAudit .button-Save").unbind("click").click(function(){
			//显示锁箱状态
			$("#financeApprove1_5 .financeApproveContent").attr("action", "submitRiskMemberAuditOpinion");
			dialog.showConfirmDialog("风控委员会审核", "是否确认提交？提交后不可再次修改。", function(){
				databind.submitDom($("#financeApprove1_5 .financeApproveContent"), function(data) {
					base.alert(1, "提交成功！");
					if (productType == 2) {
						inquireBulkstockInventoryPageList();
					} else {
						router.route("main/main_finance.html?left=5&financeState=23", true);
					}
				});
			});
		});
		
		$("#operationManageAudit .button-Save").unbind("click").click(function(){
			$("#financeApprove1_5 .financeApproveContent").attr("action", "submitOperationManageAuditOpinion");
			dialog.showConfirmDialog("副总经理审核", "是否确认提交？提交后不可再次修改。", function(){
				databind.submitDom($("#financeApprove1_5 .financeApproveContent"), function(data) {
					base.alert(1, "提交成功！");
					if (productType == 2) {
						inquireBulkstockInventoryPageList();
					} else {
						router.route("main/main_finance.html?left=5&financeState=23", true);
					}
				});
			});
		});
		
		
		
//		$("#ceoAudit .button-Save").unbind("click").click(function(){
//			$("#financeApprove1_5 .financeApproveContent").attr("action", "submitCeoAuditOpinion");
//			dialog.showConfirmDialog("总经理审核", "是否确认提交？提交后不可再次修改。", function(){
//				databind.submitDom($("#financeApprove1_5 .financeApproveContent"), function(data) {
//					base.alert(1, "提交成功！");
//					router.route("main/main_finance.html?left=0&financeState=1", true);
//				});
//			});
//		});
//		
//		$("#finalAudit .button-Save").unbind("click").click(function(){
//			$("#financeApprove1_5 .submitFinalAuditOpinion").attr("action", "submitCeoAuditOpinion");
//			dialog.showConfirmDialog("执行董事审核", "是否确认提交？提交后不可再次修改。", function(){
//				databind.submitDom($("#financeApprove1_5 .financeApproveContent"), function(data) {
////					base.alert(1, "提交成功！");
////					router.route("main/main_finance.html?left=0&financeState=1", true);
//					$(".footButton .button-Yes").trigger("click");
//				});
//			});
//		});
		//--------------------------------------------

		$("#financeApprove1_5").on("change", ".financeAmountInput", function() {
			var d = $("#financeApprove1_5 .financeAmountInput").val();
			var cm = $("#financeApprove1_5 .data[name=creditLineRemains]").html();
			
			if ((d/10000)*1 > cm*1) {
				base.alert(2, "授信额度不足！");
				return;
			}
			
			var bailRate = $("#bailRate").val();
			var $this = $(this);
			if (isNaN($this.val() * bailRate / 100)) {
//				base.alert(2, "请输入正确的金额！");
			} else {
				$("#bail").val(($this.val() * bailRate / 100).toFixed(2));
			}
			var bp = 0;
			$.each($("#financeApprove1_5 .evaluateValuation"), function() {
				bp = bp*1 + $(this).val()*1;
			});
			if (bp == 0) {
				$("#financeApprove1_5 .pledgeRate").val(0);
			} else {
				$("#financeApprove1_5 .pledgeRate").val(($("#financeApprove1_5 input[name=financeAmount]").val()*100/bp).toFixed(2));
			}
			
			$("#financeApprove1_5 input[name=bail]").val($("#financeApprove1_5 input[name=bailRate]").val()*$("#financeApprove1_5 input[name=finalPrice]").val()/100);
			if (!isNaN($("#financeApprove1_5 input[name=finalPrice]").val()) && !isNaN($("#financeApprove1_5 input[name=bail]").val())) {
				$("#financeApprove1_5 .realBailRate").val(($("#financeApprove1_5 input[name=bail]").val())/$("#financeApprove1_5 input[name=finalPrice]").val()*100);
			}
		});

		$(".button-No").on("click", function() {
			$(".financeApproveContent").attr("action", "opposeFinanceApplication");
			databind.submitDom($(".financeApproveContent"), function() {
				base.alert(1, "融资评审拒绝成功");
				router.route("main/main_finance.html?left=0&financeState=1", true);
			});
		});
		
		//查看企业详情
		$(".tab1").on("click", ".enterpriseDetail", function() {
			var enterpriseId = $("#enterpriseId").val();
			storage.setItem("enterpriseId", enterpriseId);
			window.open("../client/clientManageDetailIntact.html");
		});
		
		if (type == "editPro") {
			$(".financeProductBody input[name=financeId]").val(financeId);
			$(".financeProductBody input[name=financeAuditId]").val(financeAuditId);
			databind.enableInput($(".financeProductBody"));
			$(".saveProductInfo").removeClass("none");
			
			$(".saveProductInfo").unbind("click").click(function(){
				databind.submitDom($(".financeProductBody"), function(){
					base.alert(1, "保存成功！");
					router.route("main/main_finance.html?left=0&financeState=1", true);
				});
			});
		} else {
			$(".financeProductBody input[name=financeId]").remove();
			$(".financeProductBody input[name=financeAuditId]").remove();
		}
	}
	
	//查询融资评审信息
	var inquireFinanceLatestAuditDetail = function() {
		base.fnAjax({
			action: "inquireFinanceLatestAuditDetail.json",
			oData: {
				financeId: financeId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					databind.fillForm($(".financeApproveContent"), data.datas[0]);
					$(".financeNumber").html(data.datas[0].financeNumber);
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	};
	
	//权限控制
    var inquireCurrentOperationList = function(){
        base.fnAjax({
            action: 'inquireCurrentOperationList.json',
            async:false,
            fnSuccess: function (data) {
                if (data.status == 200) {
                    for(var i=0;i<data.datas.length;i++){
                        var permission = data.datas[i];
                        var permissionId = permission.permissionId;
                        $.each($("#financeApprove1_5").find("input"), function() {
                        	var $this = $(this);
                        	if($this.attr("permissionId") == permissionId){
                        		$this.removeClass("none");
                        	}
                        });
                    }
                } else {
                    base.alert(3, data.message);
                }
            }
        });
    };
    
    //查询融资箱货列表
    var inquireBulkstockInventoryPageList = function(){
        base.fnAjax({
            action: 'inquireBulkstockInventoryPageList.json',
            async:false,
            oData: {
				financeId: financeId,
				pageSize: 10000,
				inventoryLockState: true
			},
            fnSuccess: function (data) {
                if (data.status == 200) {
                	layer.open({
                	  area: ['620px', '640px'], //宽高
					  title: "加锁状态",
					  type: 1,
					  skin: 'layui-layer-demo', //样式类名
					  closeBtn: 1, //不显示关闭按钮
					  anim: 2,
					  shadeClose: true, //开启遮罩关闭
					  content: html_inventoryList,
					  end: function(){
					  	router.route("main/main_finance.html?left=5&financeState=23", true);
					  }
					});
                	var tpl = $("#html_inventoryList script").html();
                	var html = juicer(tpl, data);
                	$("#html_inventoryList table").html(html);
                } else {
                    base.alert(3, data.message);
                }
            }
        });
    };
	
	//上传文件
	var uploadFile = function() {
		if ($("#auditFile").val() != "") {
			$.ajaxFileUpload({
				url: "/finance/api/v1.0/uploadFile.json", //你处理上传文件的服务端
				secureuri: false,
				fileElementId: 'auditFile',
				dataType: 'json',
				success: function(data) {
					var str = '<div class="showAuditIntroDiv"><a target="_blank" class="mas" fileUuid="' + data.data[0].fileUuid + '" href="/finance/api/v1.0/downloadFile.file?fileUuid=' + data.data[0].fileUuid + '" class="showAuditIntro">' + data.data[0].fileName + '</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="deleteProductIntro">x</a></div>'
					$(".auditFile").before(str);
					fileUuid = [];
					for (var j = 0; j < $(".showAuditIntroDiv .mas").length; j++) {
						fileUuid.push($($(".showAuditIntroDiv .mas")[j]).attr("fileUuid"));
					}
					$("#auditMaterials").val(fileUuid);
				},
				complete: function(xml) {
					$("#auditFile").change(function() {
						uploadFile();
					});
				},
				error: function(data, status, e) {
					if (data.msg == null) {
						base.alert(2, "文件太大无法上传");
					} else {
						base.alert(2, data.msg);
					}
				}
			});
		} else {
			base.alert(3, "请选择文件！");
		}
	};
	
	//查询融资基本信息
	var inquireFinanceApplicationDetail = function() {
		base.fnAjax({
			action: "inquireFinanceApplicationDetail.json",
			oData: {
				financeId: financeId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					productType = data.datas[0].productType;
					
					juicer.register("inquireFile", tools.inquireFile);
					juicer.register("getValueByKey", constant.getValueByKey);
					juicer.register("formatCurrency", tools.formatCurrency);
					
					if(data.datas[0].financeAuditDetail != null) {
						var financeAuditId = data.datas[0].financeAuditDetail.financeAuditId;
					}
					
					if (financeAuditId != null || financeAuditId == 0) {
						databind.fillInput1($("#financeApprove1_5"), {action: "inquireFinanceAuditDetail.json?financeAuditId="+financeAuditId, async: true}, function(data){
							tools.barcode($("#financeApprove1_5 .barcode"), data.datas[0].auditNumber, "code128");
							
							$.each($("#financeApprove1_5 .submitState"), function() {
								var $this = $(this);
								if ($this.val() == "true") {
									$this.parent().find(".auditInfo").after("<span style='color:red; margin-left: 15px;'>已提交</span>");
								} else {
									$this.parent().find(".auditInfo").after("<span style='color:red; margin-left: 15px;'>待提交</span>");
								}
							});
							interestPart = data.datas[0].interestPart;
						});
					} else {
//						$("#financeApprove1_5 #businessManageAudit .button-Yes").remove();
//						$("#financeApprove1_5 #riskAudit .button-Yes").remove();
//						$("#financeApprove1_5 #operationAudit .button-Yes").remove();
//						$("#financeApprove1_5 #operationManageAudit .button-Yes").remove();
//						$("#financeApprove1_5 #financialAudit .button-Yes").remove();
//						$("#financeApprove1_5 #financialManageAudit .button-Yes").remove();
//						$("#financeApprove1_5 #riskMemberAudit .button-Yes").remove();
//						$("#financeApprove1_5 #ceoAudit .button-Yes").remove();
//						$("#financeApprove1_5 #finalAudit .button-Yes").remove();
//						
//						$("#financeApprove1_5 #businessManageAudit .button-Save").remove();
//						$("#financeApprove1_5 #riskAudit .button-Save").remove();
//						$("#financeApprove1_5 #operationAudit .button-Save").remove();
//						$("#financeApprove1_5 #operationManageAudit .button-Save").remove();
//						$("#financeApprove1_5 #financialAudit .button-Save").remove();
//						$("#financeApprove1_5 #financialManageAudit .button-Save").remove();
//						$("#financeApprove1_5 #riskMemberAudit .button-Save").remove();
//						$("#financeApprove1_5 #ceoAudit .button-Save").remove();
//						$("#financeApprove1_5 #finalAudit .button-Save").remove();
//						$("#financeApprove1_5 input[name=financeAmount]").attr("isNull", "1");
//						$("#financeApprove1_5 input[name=financeAmount]").attr("isNull", "1");
						
					}
					
//					if (data.datas[0].productId != null && data.datas[0].productId != 0) {
//						data.datas[0].bailRate = inquireFinanceProductDetail(data.datas[0].productId);
//					}
					databind.fillForm($(".financeApproveContent"), data.datas[0]);
					$(".interest").val(data.datas[0].interest);
					$(".financeNumber").html(data.datas[0].financeNumber);
					var html;
					var financeDetailApproveTpl = $("#financeDetailApproveTpl").html();
					if (financeDetailApproveTpl != undefined) {
						html = juicer(financeDetailApproveTpl, data);
					}
					$(".pledging_goods_Approve").append(html);
					
//					if (data.datas[0].productType != 3) {
						var inventoryListTpl = $("#inventoryListTpl").html();
						if (inventoryListTpl != undefined) {
							var html1 = juicer(inventoryListTpl, data);
							$(".pledging_goods_Approve").append(html1);
						}
//					}
					
					$("#financeApprove1_5").on("change", ".interest", function() {
						$("#financeApprove1_5 .serveExpense").html($("#financeApprove1_5 .financeAmountInput").val()*$("#financeApprove1_5 .interest").val()/100);
					});
					
					$("#financeApprove1_5").on("change", ".financeAmountInput", function() {
						$("#financeApprove1_5 .serveExpense").html($("#financeApprove1_5 .financeAmountInput").val()*$("#financeApprove1_5 .interest").val()/100);
					});

					$(".applicationAmount").html(tools.formatCurrency(data.datas[0].applicationAmount));
					$(".applicationAmount").after("(" + tools.changeMoneyToChinese(data.datas[0].applicationAmount) + ")");

					$(".showcoldStorage").unbind("click").click(function() {
						var $this = $(this);
						var ds = [];
						var d = {};
						d.precool = $this.attr("precool");
						d.ptiOk = $this.attr("ptiOk");
						d.plug = $this.attr("plug");
						d.plugType = $this.attr("plugType");
						d.tempUpDown = $this.attr("tempUpDown");
						d.setTemperature = $this.attr("setTemperature");
						d.tempUnit = $this.attr("tempUnit");
						d.tempMax = $this.attr("tempMax");
						d.tempMin = $this.attr("tempMin");
						d.vent = $this.attr("vent");
						d.coolLetter = $this.attr("coolLetter");
						d.coolRemark = $this.attr("coolRemark");
						ds.push(d);
						data.ds = ds;
						$("#popdialog").html(html_coldStorage);
						$("#coldStorage_dialog .dialogTitle").html("冷藏品信息");
						var tpl = $("#coldStorageTpl").html();
						var html = juicer(tpl, data);
						$("#coldStorageBody").html(html);
						dialog.showDialog($("#coldStorage_dialog"));

						$("#coldStorage_dialog .sure_yes").unbind("click").click(function() {
							dialog.hideDialog($("#coldStorage_dialog"));
						});
					});

					$(".showDangerous").unbind("click").click(function() {
						var $this = $(this);
						var ds = [];
						var d = {};
						d.declaration = $this.attr("declaration");
						d.instructionManual = $this.attr("instructionManual");
						d.dangerousRemark = $this.attr("dangerousRemark");
						d.unNum = $this.attr("unNum");
						d.imdg = $this.attr("imdg");
						ds.push(d);
						data.ds1 = ds;
						$("#popdialog").html(html_coldStorage);
						$("#coldStorage_dialog .dialogTitle").html("危险品信息");
						juicer.register("getValueByKey", constant.getValueByKey);
						var tpl = $("#dangerousTpl").html();
						var html = juicer(tpl, data);
						$("#coldStorageBody").html(html);
						dialog.showDialog($("#coldStorage_dialog"));

						$("#coldStorage_dialog .sure_yes").unbind("click").click(function() {
							dialog.hideDialog($("#coldStorage_dialog"));
						});
					});

					$.each($("#accountDetail table"), function() {
						var $this = $(this);
						if ($this.find("tr").length == 1) {
							$this.remove();
						}
					});
					
					$.each($(".auditInfo .data"), function() {
						var $this = $(this);
						if ($.trim($this.html()) == "") {
							$this.parents(".auditInfo").hide();
						}
					});
					
					databind.fillForm($("#financeApprove1_5 .enterpriseInsuranceInfo"), data.datas[0]);
					databind.disableInput($("#financeApprove1_5 .enterpriseInsuranceInfo"));
					
					if (financeAuditId != null && financeAuditId != "") {
						databind.fillInput1($("#financeApprove1_5"), {action: "inquireFinanceAuditDetail.json?financeAuditId=" + financeAuditId}, function(data){
							$("#financeApprove1_5 input[name=financeAmount]").val(data.datas[0].financeAmount);
//							$.each($("#auditMaterials").val().split(','), function() {
//								if (this != "") {
//									var str = '<div class="showAuditIntroDiv"><a target="_blank" class="mas" fileUuid="' + this + '" href="/finance/api/v1.0/downloadFile.file?fileUuid=' + this + '" class="showAuditIntro">' + tools.inquireFile(this) + '</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="deleteProductIntro">x</a></div>'
//									$(".auditFile").before(str);
//								}
//							});
						});
					}
					
					var bulkstocksTpl = $("#bulkstocksTpl").html();
					if (bulkstocksTpl != undefined) {
						html = juicer(bulkstocksTpl, data.datas[0]);
					}
					$(".bulkstocks").append(html);
					
					//估值
					$(".financeApproveValuation").unbind("click").click(function() {
						var unit = "";
						var quantity = 0;
						if ($(this).attr("measurement") == 1) {
							unit = "体积：";
							quantity = $(this).attr("volume");
						} else if ($(this).attr("measurement") == 2) {
							unit = "重量：";
							quantity = $(this).attr("weight");
						}
						valuationCal.showCal("货物估值", $(this).attr("bulkstockInfoId"), unit, quantity, $(this).parent().find(".evaluateValuation"), $(this).parent().find(".evaluatePrice"), $(this).attr("conversionFactor"), function(){
							var bp = 0;
							$.each($("#financeApprove1_5 input[name=evaluateValuation]"), function() {
								bp = bp*1 + $(this).val()*1;
							});
							
							if (bp == 0) {
								$("#financeApprove1_5 .pledgeRate").val(0);
							} else {
								$("#financeApprove1_5 .pledgeRate").val(($("#financeApprove1_5 input[name=financeAmount]").val()*100/bp).toFixed(2));
							}
						});
					});
					
					$.each(data.datas[0].financeContractDetail.materials.split(','), function() {
						var _this = this;
						if($.trim(_this) != "") {
							var str = '<div class="showAuditIntroDiv"><a target="_blank" class="mas" fileUuid="' + _this + '" href="/finance/api/v1.0/downloadFile.file?fileUuid=' + _this + '" class="showAuditIntro">' + tools.inquireFile(_this) + '</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="deleteProductIntro">x</a></div>'
							$("#financeApprove1_5 .financeContract").append(str);
						}
						
					});
					
					$.each(data.datas[0].financeProtocolDetail.materials.split(','), function() {
						var _this = this;
						if($.trim(_this) != "") {
							var str = '<div class="showAuditIntroDiv"><a target="_blank" class="mas" fileUuid="' + _this + '" href="/finance/api/v1.0/downloadFile.file?fileUuid=' + _this + '" class="showAuditIntro">' + tools.inquireFile(_this) + '</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="deleteProductIntro">x</a></div>'
							$("#financeApprove1_5 .financeProtocol").append(str);
						}
						
					});
					
					//产品信息
					var tpl = $("#financeApprove1_5 .financeProductTpl").html();
					var html = juicer(tpl, data);
					$("#financeApprove1_5 .financeProductBody").html(html);
					
					$.each($("#financeApprove1_5 .financeProductBody select"), function() {
						$(this).val($(this).attr("value"));
					});
					
//					databind.fillInput1($("#financeApprove1_5 .creditLineDom"), {action: "inquireEnterpriseFinanceSummaryPageList.json?enterpriseId=" + data.datas[0].enterpriseId}, function(d){
//						$("#financeApprove1_5 .creditLineDom .data[name=creditLineRemains]").html(d.datas[0].creditLine*1 - d.datas[0].creditLineAlready*1);
//					});
					inquireEnterpriseDetail(data.datas[0].enterpriseId);
					
					if (type == "detail" || (data.datas[0].financeState != 1 && data.datas[0].financeState != 23)) {
						databind.disableInput($("#financeApprove1_5"));
						$(".button-submit").remove();
						$(".auditFile").remove();
						$(".deleteProductIntro").remove();
						$(".financeApproveValuation").remove();
						$(".financeFilesNormList label").remove();
					}
					
					if ($("#financeApprove1_5 select[name=productType]").val() == null) {
						$("#financeApprove1_5 select[name=productType]").val(data.datas[0].productType);
					}
					
					$("#financeApprove1_5 .serveExpense").html(tools.formatCurrency($("#financeApprove1_5 .financeAmountInput").val()*$("#financeApprove1_5 input[name=intrerst]").val()/100));
					
					if (data.datas[0].financeState == 1) {
						$("#riskAudit").remove();
						$("#riskMemberAudit").remove();
						$("#operationManageAudit").remove();
					}
					
					var bp = 0;
					$.each($("#financeApprove1_5 input[name=evaluateValuation]"), function() {
						bp = bp*1 + $(this).val()*1;
					});
					
					if (bp == 0) {
						$("#financeApprove1_5 .pledgeRate").val(0);
					} else {
						$("#financeApprove1_5 .pledgeRate").val(($("#financeApprove1_5 input[name=financeAmount]").val()*100/bp).toFixed(2));
					}
					
					if ($("#financeApprove1_5 select[name=productType]").val() == 2) {
						$("#financeApprove1_5 input[name=bail]").attr("readonly", "readonly");
					}
					
					inquireSystemParamByName("计息期间分段");
					
					if (type == "editPro") {
						$(".financeProductBody input[name=financeId]").val(financeId);
						$(".financeProductBody input[name=financeAuditId]").val(financeAuditId);
						databind.enableInput($(".financeProductBody"));
						$(".saveProductInfo").removeClass("none");
						
						$(".saveProductInfo").unbind("click").click(function(){
							databind.submitDom($(".financeProductBody"), function(){
								base.alert(1, "保存成功！");
								router.route("main/main_finance.html?left=0&financeState=1", true);
							});
						});
					} else {
						$(".financeProductBody input[name=financeId]").remove();
						$(".financeProductBody input[name=financeAuditId]").remove();
					}
					
					if ($("#businessAudit .submitState").val() == "false" || $("#businessAudit .submitState").val() == "") {
						$("#businessManageAudit .button-submit").remove();
						$("#riskAudit .button-submit").remove();
						$("#riskMemberAudit .button-submit").remove();
						$("#operationAudit .button-submit").remove();
					} 
					else if ($("#businessManageAudit .submitState").val() == "false") {
						$("#riskAudit .button-submit").remove();
						$("#riskMemberAudit .button-submit").remove();
						$("#operationAudit .button-submit").remove();
					} 
					else if ($("#operationAudit .submitState").val() == "false") {
						$("#riskAudit .button-submit").remove();
						$("#riskMemberAudit .button-submit").remove();
					} 
					else if ($("#riskAudit .submitState").val() == "false") {
						$("#riskMemberAudit .button-submit").remove();
					}
					
					if (financeAuditId != 0 && financeAuditId != null) {
						var d = {};
						d.datas = data.datas[0].financeFilesInfoList;
						var tpl = $("#financeApprove1_5 .financeFilesNormListTpl").html();
						var html = juicer(tpl, d);
						$("#financeApprove1_5 .financeFilesNormList").html(html);
						
						$.each($("input[name=filesUuid]"), function(){
							var $this = $(this);
							$.each($(this).val().split(","), function() {
								var _this = this;
								if ($.trim(_this) != "") {
									var str = '<div class="showProductIntroDiv"><a target="_blank" class="mas" fileUuid="' + _this + '" href="/finance/api/v1.0/downloadFile.file?fileUuid=' + _this + '" class="showProductIntro">' + tools.inquireFile(_this) + '</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);" class="deleteProductIntro">x</a></div>'
									$this.parent().find("label").before(str);
								}
							});
						});
						
						$.each($("#financeApprove1_5 .normFile"), function() {
							tools.fileupload($("#"+$(this).attr("id")), null, function(data, dom){
								var str = '<div class="showProductIntroDiv"><a target="_blank" class="mas" fileUuid="' + data.result.data[0].fileUuid + '" href="/finance/api/v1.0/downloadFile.file?fileUuid=' + data.result.data[0].fileUuid + '" class="showProductIntro">' + data.result.data[0].fileName + '</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);" class="deleteProductIntro">x</a></div>'
								$("#"+$(dom).attr("id")).parent().find("label").before(str);
								fileUuid = [];
								for (var j = 0; j < $("#"+$(dom).attr("id")).parent().find(".showProductIntroDiv .mas").length; j++) {
									fileUuid.push($($("#financeApprove1_5 .showProductIntroDiv .mas")[j]).attr("fileUuid"));
								}
								$("#"+$(dom).attr("id")).parent().find("input[name=filesUuid]").val(fileUuid);
							});
						});
					}
					
					if (data.datas[0].productType == 4) {
						$(".bulkstocks .pledging_goods").remove();
						if (financeAuditId == null) {
							$("input[name=evaluateValuation]").val(data.datas[0].valuation);
							$("input[name=lowestPrice]").val(data.datas[0].valuation);
							$("input[name=highestPrice]").val(data.datas[0].valuation);
							$("input[name=financeAmount]").val(data.datas[0].applicationAmount);
						}
						$(".productTable").parent().remove();
						$(".pledging_goods p:last").html("运费信息");
						$(".ferightInfo").removeClass("none");
					} else if (data.datas[0].productType == 1) {
						//TODO 代采模式下显示信息
					}
					
					if (data.datas[0].productType != 1 && data.datas[0].productType != 5) {
						$("#operationAudit").remove();
					}
					
					//实际保证金比例
					$("#financeApprove1_5").on("keyup", "input[name=finalPrice]", function(){
						if (!isNaN($("#financeApprove1_5 input[name=finalPrice]").val()) && !isNaN($("#financeApprove1_5 input[name=bail]").val())) {
							$("#financeApprove1_5 .realBailRate").val(($("#financeApprove1_5 input[name=bail]").val())/$("#financeApprove1_5 input[name=finalPrice]").val()*100);
						}
					});
					$("#financeApprove1_5").on("keyup", "input[name=bail]", function(){
						if (!isNaN($("#financeApprove1_5 input[name=finalPrice]").val()) && !isNaN($("#financeApprove1_5 input[name=bail]").val())) {
							$("#financeApprove1_5 .realBailRate").val(($("#financeApprove1_5 input[name=bail]").val())/$("#financeApprove1_5 input[name=finalPrice]").val()*100);
						}
					});
					
					$("#financeApprove1_5 .realBailRate").val(($("#financeApprove1_5 input[name=bail]").val())/$("#financeApprove1_5 input[name=finalPrice]").val()*100);
					
					//质押单价
					$("#financeApprove1_5").on("keyup", ".financeAmountInput", function(){
						var $this = $(this);
						if (!isNaN($this.val())) {
							$("#financeApprove1_5 .financePrice").val($this.val()/data.datas[0].bulkstocks[0].quantity);
						}
					});
					
					//触发补仓单价&跌价补偿金额&跌价补偿数量
					$("#financeApprove1_5").on("keyup", "input[name=finalPrice]", function(){
						if (!isNaN($("#financeApprove1_5 select[name=priceFactor]").val()) && !isNaN($("#financeApprove1_5 input[name=finalPrice]").val())) {
							$("#financeApprove1_5 .coverPrice").val($("#financeApprove1_5 input[name=finalPrice]").val()*(1-($("#financeApprove1_5 select[name=priceFactor]").val()/100))/(data.datas[0].bulkstocks[0].quantity));
							$("#financeApprove1_5 .coverAmount").val((($("#financeApprove1_5 .latestPrice").val() - $("#financeApprove1_5 .coverPrice").val())*data.datas[0].bulkstocks[0].quantity));
							$("#financeApprove1_5 .coverQuantity").val($("#financeApprove1_5 .coverAmount").val()/$("#financeApprove1_5 .latestPrice").val());
						}
					});
					$("#financeApprove1_5").on("change", "select[name=priceFactor]", function(){
						if (!isNaN($("#financeApprove1_5 select[name=priceFactor]").val()) && !isNaN($("#financeApprove1_5 input[name=finalPrice]").val())) {
							$("#financeApprove1_5 .coverPrice").val($("#financeApprove1_5 input[name=finalPrice]").val()*(1-($("#financeApprove1_5 select[name=priceFactor]").val()/100))/(data.datas[0].bulkstocks[0].quantity));
							$("#financeApprove1_5 .coverAmount").val((($("#financeApprove1_5 .latestPrice").val() - $("#financeApprove1_5 .coverPrice").val())*data.datas[0].bulkstocks[0].quantity));
							$("#financeApprove1_5 .coverQuantity").val($("#financeApprove1_5 .coverAmount").val()/$("#financeApprove1_5 .latestPrice").val());
						}
					});
					
					$("#financeApprove1_5 .bulkstockQuantity").val(data.datas[0].bulkstocks[0].quantity);//质物数量
					inquireBulkstockLatestCollectionList(data.datas[0].bulkstocks[0].bulkstockInfoId);//质物实时单价
					inquireFinanceBulkstockPledgeRate(data.datas[0].enterpriseId, data.datas[0].bulkstocks[0].bulkstockInfoId, productType);
					if (!isNaN($("#financeApprove1_5 select[name=priceFactor]").val()) && !isNaN($("#financeApprove1_5 input[name=finalPrice]").val())) {
						$("#financeApprove1_5 .coverPrice").val($("#financeApprove1_5 input[name=finalPrice]").val()*(1-($("#financeApprove1_5 select[name=priceFactor]").val()/100))/(data.datas[0].bulkstocks[0].quantity));
						$("#financeApprove1_5 .coverAmount").val((($("#financeApprove1_5 .latestPrice").val() - $("#financeApprove1_5 .coverPrice").val())*data.datas[0].bulkstocks[0].quantity));
						$("#financeApprove1_5 .coverQuantity").val($("#financeApprove1_5 .coverAmount").val()/$("#financeApprove1_5 .latestPrice").val());
					}
					if (!isNaN($("#financeApprove1_5 .financeAmountInput").val())) {
						$("#financeApprove1_5 .financePrice").val($("#financeApprove1_5 .financeAmountInput").val()/data.datas[0].bulkstocks[0].quantity);
					}
					
					tools.clearNoNumAll($("#financeApprove1_5"));	
					$("select[name=settlementMethod]").val(data.datas[0].settlementMethod);
					$("select[name=interestPart]").val(interestPart);
					if (data.datas[0].financeProductInnerDetail != null && data.datas[0].financeProductInnerDetail.financeProductId != 0) {
						$("input[name=bailRate]").val(data.datas[0].financeProductInnerDetail.bailRate);
					}
					if (!isNaN($("#financeApprove1_5 input[name=finalPrice]").val()) && !isNaN($("#financeApprove1_5 input[name=financeAmount]").val())) {
						var am = ($("#financeApprove1_5 input[name=finalPrice]").val()-$("#financeApprove1_5 input[name=financeAmount]").val())/$("#financeApprove1_5 input[name=finalPrice]").val()*100;
						if (!isNaN(am)) {
							$("#financeApprove1_5 .realBailRate").val();
						}
					}
					
					if ($("#financeApprove1_5 input[name=businessSubmitState]").val() == "true") {
						$("#financeApprove1_5 .deleteProductIntro").remove();
						$("#financeApprove1_5 .auditFile").remove();
						$("#financeApprove1_5 .financeApproveValuation").remove();
						$("#financeApprove1_5 .financeFilesNormList label").remove();
						$("#financeApprove1_5 .normFile2").remove();
						$("#financeApprove1_5 .deleteProductIntro").remove();
						databind.disableInput($("#financeApprove1_5"));
						databind.enableInput($("#financeApprove1_5 .supplementOpinion"));
					}
					
					//保证金凭证
					if (data.datas[0].bailVoucher != null && $.trim(data.datas[0].bailVoucher) != "") {
						var str = '<div style="margin-top:15px;">保证金核销凭证:<a target="_blank" href="/finance/api/v1.0/downloadFile.file?fileUuid='+data.datas[0].bailVoucher+'">'+tools.inquireFile(data.datas[0].bailVoucher)+'</a></div>';
						$("#financeApprove1_5 #operationAudit .financing_field-lab2").after(str);
					}
					
					if (financeAuditId == null || financeAuditId == 0) {
						$("#financeApprove1_5 input[name=distrain]").val(2);
						$("#financeApprove1_5 input[name=financeDays]").val(data.datas[0].loanTimeLimit);
						$("#financeApprove1_5 select[name=settlementMethod]").val(1);
					}
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	}
	
	//查询货品质押率信息
	var inquireFinanceBulkstockPledgeRate = function(enterpriseId, bulkstockInfoId, productType) {
		base.fnAjax({
			action: "inquireFinanceBulkstockPledgeRate.json",
			async: false,
			oData: {
				enterpriseId: enterpriseId,
				bulkstockInfoId: bulkstockInfoId,
				productType: productType
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					$("#financeApprove1_5 .highestPledge").val(data.datas[0].pledgeRateCeiling);
					if (financeAuditId == null) {
						$("input[name=bailRate]").val(data.datas[0].bailRate);
					}
				} else {
					//                  base.alert(2,"信息获取失败");
				}
			}
		});
	};
	
	//大宗商品最新信息
	var inquireBulkstockLatestCollectionList = function(bulkstockInfoId) {
		base.fnAjax({
			action: "inquireBulkstockLatestCollectionList.json",
			async: false,
			oData: {
				bulkstockInfoId: bulkstockInfoId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					if (data.datas.length > 0) {
						$("#financeApprove1_5 .latestPrice").val(data.datas[0].price);
					}
				} else {
					//                  base.alert(2,"信息获取失败");
				}
			}
		});
	};
	
	var inquireSystemParamByName = function(paramName) {
		base.fnAjax({
			action: "inquireSystemParamByName.json",
			async: false,
			oData: {
				paramName: paramName
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					$("#financeApprove1_5 .interestPart").append("<option value=''>请选择</option>");
					$.each(data.datas[0].paramValue.split(','), function() {
						var str = "<option value='" + this + "'>" + this + "</option>";
						$("#financeApprove1_5 .interestPart").append(str);
					});
				} else {
					//                  base.alert(2,"信息获取失败");
				}
			}
		});
	};
	
	var inquireEnterpriseDetail = function(enterpriseId) {
		base.fnAjax({
			action: "inquireEnterpriseDetail.json",
			async: false,
			oData: {
				enterpriseId: enterpriseId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					databind.fillForm($("#financeApprove1_5 .creditLineDom"), data.datas[0].enterpriseGradeDetail);
					$(".data[name=creditLine]").html(($(".data[name=creditLine]").html()/10000).toFixed(2));
					$(".data[name=creditAlready]").html(($(".data[name=creditAlready]").html()/10000).toFixed(2));
					$(".data[name=creditLineRemains]").html(($(".data[name=creditLineRemains]").html()/10000).toFixed(2));
				} else {
					//                  base.alert(2,"信息获取失败");
				}
			}
		});
	};
	
	//查询所需附件
	var inquireFinanceFilesNormList = function() {
		base.fnAjax({
			action: "inquireFinanceFilesNormList.json",
			async: false,
			oData: {
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					var tpl = $("#financeApprove1_5 .financeFilesNormListTpl").html();
					var html = juicer(tpl, data);
					$("#financeApprove1_5 .financeFilesNormList").html(html);
					
					$.each($("#financeApprove1_5 .normFile"), function() {
						tools.fileupload($("#"+$(this).attr("id")), null, function(data, dom){
							var str = '<div class="showProductIntroDiv"><a target="_blank" class="mas" fileUuid="' + data.result.data[0].fileUuid + '" href="/finance/api/v1.0/downloadFile.file?fileUuid=' + data.result.data[0].fileUuid + '" class="showProductIntro">' + data.result.data[0].fileName + '</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);" class="deleteProductIntro">x</a></div>'
							$("#"+$(dom).attr("id")).parent().find("label").before(str);
							fileUuid = [];
							for (var j = 0; j < $("#financeApprove1_5 .showProductIntroDiv .mas").length; j++) {
								fileUuid.push($($("#financeApprove1_5 .showProductIntroDiv .mas")[j]).attr("fileUuid"));
							}
							$("#"+$(dom).attr("id")).parent().find("input[name=filesUuid]").val(fileUuid);
						});
					});
				} else {
				}
			}
		});
	};

	return {
		init: init
	};
});